// pages/check/detail/doneDetail.js
const util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showIndex1: 1,//巡检计划面板展开
    showIndex2: 2,//巡检执行面板展开
    obj:null,
    loadingHidden:false
  },
  //预览图片
  imgYu(event) {
    util.imgYu2(event);
  },
  //工单信息面板折叠展开操作
  panel: function (e) {
    var i = 0
    if (e.currentTarget.dataset.index == 1) {
      if (e.currentTarget.dataset.index != this.data.showIndex1)
        i = e.currentTarget.dataset.index;
      this.setData({
        showIndex1: i
      })
    } else if (e.currentTarget.dataset.index == 2) {
      if (e.currentTarget.dataset.index != this.data.showIndex2)
        i = e.currentTarget.dataset.index;
      this.setData({
        showIndex2: i
      })
    }
  },
  // 巡检详情接口：/api/polling/get-polling-record-info 
  //获取详情信息
  doGetData(id){
    let _this = this;
    _this.setData({
      loadingHidden:  false
    })
    wx.request({
      url: getApp().data.app_server + "/weixin/polling/get-polling-record-info",
      method: 'post',
      data: {id:id},
      success: function (res) {
        console.log(res);
        let data = res.data.msg;
        var name = '';
        if (data.inspectionImplementUsers != null) { 
          for (var j = 0; j < data.inspectionImplementUsers.length; j++) {
            name = data.inspectionImplementUsers[j].userName + ',' + name;
          }
          name = name.substr(0, name.length - 1);
          data.inspectionImplementUsers = name;
        }
        data.inspectionPlanEntity.inspectionStartDate = util.formatTimeStamp(data.inspectionPlanEntity.inspectionStartDate, 'Y-M-D h:m');
        data.inspectionExecute.created = util.formatTimeStamp(data.inspectionExecute.created, 'Y-M-D h:m');
        let time = data.inspectionCycle - 100;
        let flag = 2;//0超时巡检，1已逾期，2正常巡检
        let flagInspection = 1;//0 待巡检，1已巡检
        if (time < new Date().getTime()) {
          if (data.inspectionExecute) {
            flag = 0;
          } else {
            flag = 1;
          }
        }
        if (!data.inspectionExecute) {
          flagInspection = 0;
        }
        data.flagInspection = flagInspection;
        data.flag = flag;   
        //附件地址处理
        let arrUrl = data.inspectionExecute.sysAttachmentList;
        if (arrUrl != null && arrUrl.length > 0 ){
          for(var i = 0 ; i < arrUrl.length; i++){
            arrUrl[i].realPath = getApp().data.app_server + '/weixin' +arrUrl[i].filePath + arrUrl[i].id + arrUrl[i].fileType;
          }
        }
        _this.setData({
          loadingHidden: true,
          obj:data
        })
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.doGetData(options.id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})